<?php

namespace app\admin\controller\repertory;

use app\admin\controller\Controller;
use app\admin\model\repertory\BillSetting as Models;

/**
 * 账单设置
 */
class Billsetting extends Controller
{
    /**
     * 详细
     */
    public function getDetails()
    {
        $id = $this->request->param('id', 1);
        $model = Models::detail($this->dept_id);
        return $this->renderSuccess('详细', $model);
    }

    /**
     * 更新权限
     */
    public function edit()
    {
        // 权限详情
        $data = $this->postData();
        $model = Models::detail($this->dept_id);

        if ($data["flag"] == 'true') {
            $data["flag"] = 1;
        } else {
            $data["flag"] = 2;
        }

        if ($data["print"] == 'true') {
            $data["print"] = 1;
        } else {
            $data["print"] = 2;
        }

        if ($data["tax0"] == 'true') {
            $data["tax0"] = 1;
        } else {
            $data["tax0"] = 2;
        }

        if ($data["units"] == 'true') {
            $data["units"] = 1;
        } else {
            $data["units"] = 2;
        }

        $data["dept_id"] = $this->dept_id;

        // 更新记录
        if ($model->edit($data)) {
            return $this->renderSuccess('更新成功');
        }
        return $this->renderError('更新失敗');
    }

    /**
     * 删除小程序
     */
    public function delete()
    {
        $message_id = $this->request->param('id');
        // 小程序详情
        $model = Models::detail($message_id);
        if (!$model->setDelete()) {
            return $this->renderError('操作に失敗');
        }
        return $this->renderSuccess('操作成功');
    }

    /**
     * 获取模版样式
     */
    public function getTmpImgList()
    {
        $data = [
            ["id" => 1, "img" => 'https://plusone-stock.com/public/image/tmp/1.png'],
            ["id" => 2, "img" => 'https://plusone-stock.com/public/image/tmp/2.png'],
        ];
        return $this->renderSuccess('模版样式', $data);
    }
}